package com.yangjun.controller.businessAnalysis.logisticsAnalysis.packageEfficacy;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import com.yangjun.dao.impl.businessAnalysis.memberAnalysis.logisticsAnalysis.packageEfficacy.PackageEfficacyDaoImpl;
import com.yangjun.dao.mybatis.mapper.businessAnalysis.logisticsAnalysis.PackageEfficacyMapper;
import com.yangjun.entity.businessAnalysis.logisticsAnalysis.CollectGoodsFailEntity;
import com.yangjun.entity.businessAnalysis.logisticsAnalysis.HostSaleGroupDetailsEntity;
import com.yangjun.entity.businessAnalysis.logisticsAnalysis.HostSaleGroupEntity;
import com.yangjun.entity.businessAnalysis.logisticsAnalysis.HostSaleSigleEntity;
import com.yangjun.entity.businessAnalysis.logisticsAnalysis.OverviewFormEntity;
import com.yangjun.entity.businessAnalysis.logisticsAnalysis.RefundPackageDetailEntity;
import com.yangjun.service.bussiness.PackageEfficacyExportService;
import com.yangjun.utils.DvDateUtils;
import com.yangjun.utils.EchartUtils;

@Controller
@RequestMapping("/businessAnalysis/logisticsAnalysis/packageEfficacy")
public class PackageEfficacyController {
	
	@Autowired
	PackageEfficacyDaoImpl daomethod;
	
	@Autowired
	private PackageEfficacyMapper mapper;
	
	@Autowired
	PackageEfficacyExportService service;
	
	
	
	
	/**
	 * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/selectPlatform
	 * @param response
	 * @return
	 */
	 @RequestMapping(value="selectPlatform")
	 @ResponseBody
	 public List<Map<String,Object>> selectPlatform(HttpServletResponse response){
	   	 	response.setHeader("Access-Control-Allow-Origin", "*");
		return daomethod.findSingleSelectPlatform();
	 }
	
	
	/**
	 * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/overviewForm?platform=1&urgenttype=1
	 * 总况表格数据
	 * @param response
	 * @param platform
	 * @param urgenttype
	 * @return
	 */
	 @RequestMapping("/overviewForm")
	 @ResponseBody
    public OverviewFormEntity overviewForm(HttpServletResponse response,
    		@RequestParam(value = "platform",required = false)String platform,
    		@RequestParam(value = "urgenttype",required = false)String urgenttype){
    	response.setCharacterEncoding("UTF-8");
    	response.setContentType("text/html;charset=UTF-8");
    	OverviewFormEntity overviewForm = new OverviewFormEntity();
    	
       	if(StringUtils.isBlank(platform)){
    		platform="-1";
    	}
    	if(StringUtils.isBlank(urgenttype)){
    		urgenttype="-1";
    	}
    	
//    	if(StringUtils.isBlank(platform) && StringUtils.isBlank(urgenttype)){
//    		Object object = mCache.get("overview_"+platform+"_"+urgenttype+"");
//    		if(object!=null){
//    			try {
//    				overviewForm = JSONUtils.strToObj(object.toString(), OverviewFormEntity.class);
//    				OverviewFormEntity overviewFormCollectGoodsFail = mapper.overviewFormCollectGoodsFail(platform,urgenttype);
//    		    	Integer overviewFormToSynchronized = mapper.overviewFormToSynchronized(platform,urgenttype);
//    		    	if(overviewForm==null){
//    		    		overviewForm = new OverviewFormEntity();
//    		    	}
//    		    	if(overviewFormCollectGoodsFail!=null){
//    		    		overviewForm.setGather_fail_cons_qty(overviewFormCollectGoodsFail.getGather_fail_cons_qty());
//    		    		overviewForm.setGather_fail_sku(overviewFormCollectGoodsFail.getGather_fail_sku());
//    		    		overviewForm.setGather_fail_ware_qty(overviewFormCollectGoodsFail.getGather_fail_ware_qty());
//    		    	}
//    		    	if(overviewFormToSynchronized!=null){
//    		    		overviewForm.setUnsys_order_qty(overviewFormToSynchronized);
//    		    	}
////				 System.err.println(overviewForm.toString());
//    			} catch (JsonParseException e) {
//    				e.printStackTrace();
//    			} catch (JsonMappingException e) {
//    				e.printStackTrace();
//    			} catch (IOException e) {
//    				e.printStackTrace();
//    			}
//    		}
//    	}
//    	 
//    	if(overviewForm!=null){
//    		return overviewForm;
//    	}
    	
    	
    	System.out.println("platform->"+platform+"&urgenttype->"+urgenttype);
    	overviewForm = mapper.overviewForm(platform,urgenttype);
    	OverviewFormEntity overviewFormCollectGoodsFail = mapper.overviewFormCollectGoodsFail(platform,urgenttype);
    	Integer overviewFormToSynchronized = mapper.overviewFormToSynchronized(platform,urgenttype);
    	if(overviewForm==null){
    		overviewForm = new OverviewFormEntity();
    	}
    	if(overviewFormCollectGoodsFail!=null){
    		overviewForm.setGather_fail_cons_qty(overviewFormCollectGoodsFail.getGather_fail_cons_qty());
    		overviewForm.setGather_fail_sku(overviewFormCollectGoodsFail.getGather_fail_sku());
    		overviewForm.setGather_fail_ware_qty(overviewFormCollectGoodsFail.getGather_fail_ware_qty());
    	}
    	if(overviewFormToSynchronized!=null){
    		overviewForm.setUnsys_order_qty(overviewFormToSynchronized);
    	}
    	return overviewForm;
    }
	 
	 /**
	  * 
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/provinceList
	  * 获取省
	  * @param response
	  * @return
	  */
	 @RequestMapping("/provinceList")
	 @ResponseBody
	 public List<String> provinceList(HttpServletResponse response){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 return mapper.provinceList();
	 }
	 
	 /**
	  * 
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/provinceCityList?province=广东省
	  * 获取市
	  * @param response
	  * @param province
	  * @return
	  */
	 @RequestMapping("/provinceCityList")
	 @ResponseBody
	 public List<String> provinceCityList(HttpServletResponse response,
			 @RequestParam(value = "province",required = true)String province){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 return mapper.provinceCityList(province);
	 }
	 
	 
	 /**
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/CityDistrictList?city=广州市
	  * 获取区
	  * @param response
	  * @param city
	  * @return
	  */
	 @RequestMapping("/CityDistrictList")
	 @ResponseBody
	 public List<String> CityDistrictList(HttpServletResponse response,
			 @RequestParam(value = "city",required = true)String city){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 return mapper.CityDistrictList(city);
	 }
	 
	 /**
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/packageNumber?platform=&urgenttype=&column=weight_cons_qty
	  * 总况--->包裹
	  * @param response
	  * @param platform
	  * @param urgenttype
	  * @param column
	  * @return
	  */
	 @RequestMapping("/packageNumber")
	 @ResponseBody
	 public Map<String, Object>  packageNumber(HttpServletResponse response,
			 @RequestParam(value = "platform",required = false)String platform,
			 @RequestParam(value = "urgenttype",required = false)String urgenttype,
			 @RequestParam(value = "column",required = false)String column){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 Map<String, Object> resultMap = Maps.newHashMap();
		 
//		 System.err.println("urgenttype--"+urgenttype);
		 int urgenttypeValue = -1;
		 if(StringUtils.isNotBlank(urgenttype)){
			 urgenttypeValue = Integer.parseInt(urgenttype);
		 }
		 List<Map<String, Object>> packageNumberHourLast7 = daomethod.packageNumber(platform, urgenttypeValue, column,"hour",7);
		 List<Map<String, Object>> packageNumberHourToday = daomethod.packageNumber(platform, urgenttypeValue, column,"hour",1);
		 String[] h_legend = {"今日","近7日均值"};
		 
		 
		 Map<String, Object> packageNumberHourMap = EchartUtils.getBrokenOneLineMap("hour_day", "hour_day_value", h_legend, packageNumberHourLast7);
		 List<Object> signColumnHourToday = EchartUtils.getSignColumn("hour_day_value",packageNumberHourToday);
		 packageNumberHourMap.put("today", signColumnHourToday);
		 resultMap.put("package_num_hour", packageNumberHourMap);
		 
		 
		 List<Map<String, Object>> packageNumberDay30d = daomethod.packageNumber(platform, urgenttypeValue, column,"day",0);
		 Float packageNumberAvgLast7 = daomethod.packageNumberAvgLast7(platform, urgenttypeValue, column);
		 List<Float> vagLast7 = new ArrayList<Float>();
		 for(int i=0;i<30;i++){
			 vagLast7.add(packageNumberAvgLast7);
		 }
		 String[] day_legend = {"指标值","近7日均值"};
		 Map<String, Object> packageNumberDayMap = EchartUtils.getBrokenOneLineMap("hour_day", "hour_day_value", day_legend, packageNumberDay30d);
		 packageNumberDayMap.put("vagLast7", vagLast7);
		 resultMap.put("package_num_day", packageNumberDayMap);
		 return resultMap;
	 }
	 
	 /**
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/effectiveness?fromColumn=clock_sysn_weight&toColumn=weight_cons_qty
	  * 总况-->包裹时效
	  * @param response
	  * @param platform
	  * @param urgenttype
	  * @param fromColumn
	  * @param toColumn
	  * @return
	  */
	 @RequestMapping("/effectiveness")
	 @ResponseBody
	 public Map<String, Object>  packageEffectiveness(HttpServletResponse response,
			 @RequestParam(value = "platform",required = false)String platform,
			 @RequestParam(value = "urgenttype",required = false)String urgenttype,
			 @RequestParam(value = "fromto",required = false)String fromto){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 Map<String, Object> resultMap = Maps.newHashMap();
		 String fromColumn = null;
		 String toColumn = null;
		 if("already".equals(fromto)){
			 //订单到同步
			 fromColumn = "clock_order_sysn";
			 toColumn = "sys_cons_qty";
		 }else if("buildPicking".equals(fromto)){
			 //同步到创建拣货单
			 fromColumn = "clock_sysn_build";
			 toColumn = "build_cons_qty"; 
		 }else if("picking".equals(fromto)){
			 //创建到拣货开始
			 fromColumn = "clock_build_pks_fct";
			 toColumn = "pks_cons_qty_fct";
		 }else if("process".equals(fromto)){
			 //拣货开始到结束
			 fromColumn = "clock_pks_pke";
			 toColumn = "pke_cons_qty";
		 }else if("re-check".equals(fromto)){
			 //拣货结束到复核
			 fromColumn = "clock_pke_reck";
			 toColumn = "reck_cons_qty";
		 }else if("weight".equals(fromto)){
			 //复核到称重
			 fromColumn = "clock_reck_weight";
			 toColumn = "weight_cons_qty";
		 }else if("taking".equals(fromto)){
			 //称重到揽收
			 fromColumn = "clock_weight_collect";
			 toColumn = "collect_cons_qty";
		 }else{
			 //同步到称重
			 fromColumn = "clock_sysn_weight";
			 toColumn = "weight_cons_qty";
		 }
		 
//		 System.out.println("fromColumn-"+fromColumn);
//		 System.out.println("toColumn-"+toColumn);
		 
		 int urgenttypeValue = -1;
		 if(StringUtils.isNotBlank(urgenttype)){
			 urgenttypeValue = Integer.parseInt(urgenttype);
		 }
		 
		 List<Map<String, Object>> packageEffectiveness = daomethod.packageEffectiveness(platform, urgenttypeValue, fromColumn,toColumn);
		 Float packageEffectivenessAvgLast7 = daomethod.packageEffectivenessAvgLast7(platform, urgenttypeValue,  fromColumn,toColumn);
		 List<Float> vagLast7 = new ArrayList<Float>();
		 for(int i=0;i<30;i++){
			 vagLast7.add(packageEffectivenessAvgLast7);
		 }
		 String[] day_legend = {"指标值","近7日均值"};
		 Map<String, Object> packageEffectivenessMap = EchartUtils.getBrokenOneLineMap("data_date", "clock_qty_rate", day_legend, packageEffectiveness);
		 packageEffectivenessMap.put("vagLast7", vagLast7);
		 resultMap.put("package_effectiveness", packageEffectivenessMap);
		 return resultMap;
	 }
	 
	 /**
	  * 
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/expressCompanyeffectiveness
	  * 快递公司时效
	  * @param response
	  * @param platform
	  * @param urgenttype
	  * @param province
	  * @param city
	  * @param district
	  * @return
	  */
	 @RequestMapping("/expressCompanyeffectiveness")
	 @ResponseBody
	 public Map<String, Object>  expressCompanyeffectiveness(HttpServletResponse response,
			 @RequestParam(value = "platform",required = false)String platform,
			 @RequestParam(value = "urgenttype",required = false)String urgenttype,
			 @RequestParam(value = "province",required = false)String province,
			 @RequestParam(value = "city",required = false)String city,
			 @RequestParam(value = "district",required = false)String district){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 Map<String, Object> resultMap = Maps.newHashMap();
		 
//		 System.err.println(province + city + district);
		 
		 /**
		  * 当省值为全国---province = null;
		  */
		 
		 if("全国".equals(province)){
			 province=null;
		 }
		 int urgenttypeValue = -1;
		 if(StringUtils.isNotBlank(urgenttype)){
			 urgenttypeValue = Integer.parseInt(urgenttype);
		 }
		 
		 //快递公司时效
		 List<Map<String, Object>> expressCompanyEffectiveness = daomethod.expressCompanyEffectiveness(platform, urgenttypeValue, province,city,district);
		 String[] effect_legend = {"时效"};
		 Map<String, Object> expresscompanyeEffectivenessMap = EchartUtils.getBrokenOneLineMap("transfername", "clock_qty_rate", effect_legend, expressCompanyEffectiveness);
		 resultMap.put("expresscompanye_effectiveness", expresscompanyeEffectivenessMap);
		 
		 //包裹占比
		 
		 List<Map<String, Object>> packageRate = daomethod.packageRate(platform, urgenttypeValue, province,city,district);
		 resultMap.put("package_rate", EchartUtils.getBrokenOnePieMap("transfername", "sign_cons_qty", packageRate));
	    	
		 return resultMap;
	 }
	 
	 /**
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/weightDistribute?transfername=
	  * 包裹--> 重量分布 -->包裹数 与 近30天包裹出库
	  * @param response
	  * @param platform
	  * @param urgenttype
	  * @param transfername
	  * @param province
	  * @param city
	  * @param district
	  * @return
	  */
	 @RequestMapping("/weightDistribute")
	 @ResponseBody
	 public Map<String, Object>  weightDistribute(HttpServletResponse response,
			 @RequestParam(value = "platform",required = false)String platform,
			 @RequestParam(value = "urgenttype",required = false)String urgenttype,
			 @RequestParam(value = "transfername",required = false)String transfername,
			 @RequestParam(value = "province",required = false)String province,
			 @RequestParam(value = "city",required = false)String city,
			 @RequestParam(value = "district",required = false)String district){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 /**
		  * 当省值为全国---province = null;
		  */
		 
		 if("全国".equals(province)){
			 province=null;
		 }
		 
		 Map<String, Object> resultMap = Maps.newHashMap();
		 
		 int urgenttypeValue = -1;
		 if(StringUtils.isNotBlank(urgenttype)){
			 urgenttypeValue = Integer.parseInt(urgenttype);
		 }
		 
		 //包裹数-->近7日汇总
		 List<Map<String, Object>> weightDistribute = daomethod.weightDistribute(platform, urgenttypeValue,transfername, province,city,district);
		 String[] weihtt_legend = {"包裹数"};
		 Map<String, Object> weightDistributeMap = EchartUtils.getBrokenOneLineMap("wei_type", "qty", weihtt_legend, weightDistribute);
		 resultMap.put("weight_distribute", weightDistributeMap);
		 
		 //包裹数-->近7日汇总 ->占比
		 resultMap.put("weight_distribute_rate", EchartUtils.getBrokenOnePieMap("wei_type", "qty", weightDistribute));
		 
		 
		 
		 //近30天包裹出库
		
		List<Map<String, Object>> last30DayPackageOutbound = daomethod.last30DayPackageOutbound(platform,urgenttypeValue, transfername, province, city,district);
		String[] last30DayPackageOutboundLegend = {"近30天包裹出库"};
		Map<String, Object> brokenLineitemMap = EchartUtils.getBrokenOneLineMap("date_day", "qty", last30DayPackageOutboundLegend, last30DayPackageOutbound);
		resultMap.put("last30DayPackageOutbound",brokenLineitemMap);
		
		
		//进30天 药品--非药品--混合
		List<Map<String, Object>> yaopinList = daomethod.last30DayPackageOutboundDrugtype(platform,urgenttypeValue,1, transfername, province, city,district);
		List<Map<String, Object>> notyaopinList = daomethod.last30DayPackageOutboundDrugtype(platform,urgenttypeValue,2, transfername, province, city,district);
		List<Map<String, Object>> mixList = daomethod.last30DayPackageOutboundDrugtype(platform,urgenttypeValue,3, transfername, province, city,district);
		
		Map<String,Object> brokenLineitemMapYaopin = Maps.newHashMap(); 
		String[] last30DayPackageOutboundDrugtypeLegend = {"药品","非药品","混合"};
		Map<String, Object> brokenLineitemYp = EchartUtils.getBrokenOneLineMap("date_day", "qty", last30DayPackageOutboundDrugtypeLegend, yaopinList);
		brokenLineitemMapYaopin.put("yvalue_yaopin", brokenLineitemYp.get("yvalue"));
		brokenLineitemMapYaopin.put("yvalue_notyaopin", EchartUtils.getSignColumn("qty", notyaopinList));
		brokenLineitemMapYaopin.put("yvalue_mix", EchartUtils.getSignColumn("qty", mixList));
		brokenLineitemMapYaopin.put("legend",brokenLineitemYp.get("legend"));
		brokenLineitemMapYaopin.put("xAxis", brokenLineitemYp.get("xAxis"));
		
		
		resultMap.put("last30DayPackageOutboundDrugtype",brokenLineitemMapYaopin);
		    	
		return resultMap;
	 }
	 
	 /**
	  * 
	  * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/weightDistributeByWeitype?transfername=&wei_type=0.5kg
	  * 包裹-->重量分布-->点击千克
	  * @param response
	  * @param platform
	  * @param urgenttype
	  * @param transfername
	  * @param province
	  * @param city
	  * @param district
	  * @param wei_type
	  * @return
	  */
	 @RequestMapping("/weightDistributeByWeitype")
	 @ResponseBody
	 public Map<String, Object>  weightDistributeByWeitype(HttpServletResponse response,
			 @RequestParam(value = "platform",required = false)String platform,
			 @RequestParam(value = "urgenttype",required = false)String urgenttype,
			 @RequestParam(value = "transfername",required = false)String transfername,
			 @RequestParam(value = "province",required = false)String province,
			 @RequestParam(value = "city",required = false)String city,
			 @RequestParam(value = "district",required = false)String district,
			 @RequestParam(value = "wei_type",required = false)String wei_type){
		 response.setCharacterEncoding("UTF-8");
		 response.setContentType("text/html;charset=UTF-8");
		 /**
		  * 当省值为全国---province = null;
		  */
		 
		 if("全国".equals(province)){
			 province=null;
		 }
		 
		 int urgenttypeValue = -1;
		 if(StringUtils.isNotBlank(urgenttype)){
			 urgenttypeValue = Integer.parseInt(urgenttype);
		 }
		 
		 Map<String, Object> resultMap = Maps.newHashMap();
		 //包裹-->重量分布-->点击事件(点击千克)
		 
//		String[] weitype_legend = {"包裹数","占比"};
//		Date offsetDaystart = DvDateUtils.getOffsetDay(new Date(),-31);
//		Date offsetDayend = DvDateUtils.getOffsetDay(new Date(),-1);
//		List<String> datesBetweenTwoDate = DvDateUtils.getDatesBetweenTwoDate(offsetDaystart,offsetDayend,"MM-dd");
//		
//		List<Map<String, Object>> weightDistributeByWeitype = daomethod.weightDistributeByWeitype(platform, urgenttypeValue,transfername, province,city,district, wei_type);
//		Map<String,Object> brokenLineitemMap = Maps.newHashMap(); 
//		brokenLineitemMap.put("bar_value", EchartUtils.getSignColumnOfYvalueFloatSz("data_date","qty",weightDistributeByWeitype,datesBetweenTwoDate));
//		brokenLineitemMap.put("line_value", EchartUtils.getSignColumnOfYvalueFloatSz("data_date","rate",weightDistributeByWeitype,datesBetweenTwoDate));
//		brokenLineitemMap.put("legend",weitype_legend);
//		brokenLineitemMap.put("xAxis", datesBetweenTwoDate);
//		resultMap.put("bar_line",brokenLineitemMap);
		 
		 
		 String[] weitype_legend = {"包裹数","占比"};
		 Map<String,Object> brokenLineitemMap = Maps.newHashMap(); 
	     List<Map<String, Object>> weightDistributeByWeitype = daomethod.weightDistributeByWeitype(platform, urgenttypeValue,transfername, province,city,district, wei_type);
	     Map<String, Object> weightDistributeByWeitypeMap = EchartUtils.getBrokenOneLineMap("data_date", "qty", weitype_legend, weightDistributeByWeitype);
	     brokenLineitemMap.put("bar_value", weightDistributeByWeitypeMap.get("yvalue"));
	     brokenLineitemMap.put("line_value", EchartUtils.getSignColumn("rate", weightDistributeByWeitype));
	     brokenLineitemMap.put("legend",weightDistributeByWeitypeMap.get("legend"));
	     brokenLineitemMap.put("xAxis", weightDistributeByWeitypeMap.get("xAxis"));
	     resultMap.put("bar_line",brokenLineitemMap);
		 return resultMap;
	 }
 
	 
	 
	 
	
	/**
	 * 退货包裹明细
	 * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/refundPackage?pageNum=1&pageSize=3
	 * @param response
	 * @param contrastday
	 * @param platform
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
    @RequestMapping("/refundPackage")
    @ResponseBody
    public PageInfo<RefundPackageDetailEntity> refundPackage(HttpServletResponse response,
    		@RequestParam(value = "platform",required = false)String platform,
    		@RequestParam(value = "pageNum",required = true)String pageNum,
    		@RequestParam(value = "pageSize",required = true)String pageSize){
    	response.setCharacterEncoding("UTF-8");
    	response.setContentType("text/html;charset=UTF-8");
    	PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize),true,true,true);
    	PageInfo<RefundPackageDetailEntity> page = new PageInfo<RefundPackageDetailEntity>(mapper.refundPackage(platform));
    	return page;
    }
    
    
    /**
     * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/collectGoodsFail?pageNum=1&pageSize=3
     * @param response
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/collectGoodsFail")
    @ResponseBody
    public PageInfo<CollectGoodsFailEntity> collectGoodsFail(HttpServletResponse response,
    		@RequestParam(value = "pageNum",required = true)String pageNum,
    		@RequestParam(value = "pageSize",required = true)String pageSize){
    	response.setCharacterEncoding("UTF-8");
    	response.setContentType("text/html;charset=UTF-8");
    	
    	PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize),true,true,true);
    	PageInfo<CollectGoodsFailEntity> page = new PageInfo<CollectGoodsFailEntity>(mapper.collectGoodsFail());
    	return page;
    }
    
    /**
     * 
     * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/hostSaleGroup?pageNum=1&pageSize=3&cycle=today/last7
     * 热销组合
     * @param response
     * @param contrastday
     * @param platform
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/hostSaleGroup")
    @ResponseBody
    public PageInfo<HostSaleGroupEntity> hostSaleGroup(HttpServletResponse response,
    		@RequestParam(value = "platform",required = false)String platform,
    		@RequestParam(value = "urgenttype", required = false) String urgenttype,
    		@RequestParam(value = "cycle", required = false) String cycle,
    		@RequestParam(value = "pageNum",required = true)String pageNum,
    		@RequestParam(value = "pageSize",required = true)String pageSize){
    	response.setCharacterEncoding("UTF-8");
    	response.setContentType("text/html;charset=UTF-8");
    	
    	
    	PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize),true,true,true);
    	PageInfo<HostSaleGroupEntity> page = new PageInfo<HostSaleGroupEntity>(mapper.hostSaleGroup(platform,urgenttype,cycle));
    	return page;
    }
    
    /**
     * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/hostSaleGroupDetails?kitcode=10000193810
     * 热销商品组合详情
     * @param response
     * @param platform
     * @param urgenttype
     * @param cycle
     * @param kitcode
     * @return
     */
    @RequestMapping("/hostSaleGroupDetails")
    @ResponseBody
    public List<HostSaleGroupDetailsEntity> hostSaleGroupDetails(HttpServletResponse response,
    		@RequestParam(value = "platform",required = false)String platform,
    		@RequestParam(value = "urgenttype", required = false) String urgenttype,
    		@RequestParam(value = "cycle", required = false) String cycle,
    		@RequestParam(value = "kitcode",required = true)String kitcode){
    	response.setCharacterEncoding("UTF-8");
    	response.setContentType("text/html;charset=UTF-8");
    	List<HostSaleGroupDetailsEntity> hostSaleGroupDetailsList = mapper.hostSaleGroupDetails(platform,urgenttype,cycle,kitcode);
    	return hostSaleGroupDetailsList;
    }
    
    /**
     * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/hostSaleSigle?pageNum=1&pageSize=3&cycle=today/last7
     * 热销单品
     * @param response
     * @param platform
     * @param urgenttype
     * @param cycle
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("/hostSaleSigle")
    @ResponseBody
    public PageInfo<HostSaleSigleEntity> hostSaleSigle(HttpServletResponse response,
    		@RequestParam(value = "platform",required = false)String platform,
    		@RequestParam(value = "urgenttype", required = false) String urgenttype,
    		@RequestParam(value = "cycle", required = false) String cycle,
    		@RequestParam(value = "pageNum",required = true)String pageNum,
    		@RequestParam(value = "pageSize",required = true)String pageSize){
    	response.setCharacterEncoding("UTF-8");
    	response.setContentType("text/html;charset=UTF-8");
    	
//    	System.out.println("hostSaleSigle-->"+cycle);
    	PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize),true,true,true);
    	PageInfo<HostSaleSigleEntity> page = new PageInfo<HostSaleSigleEntity>(mapper.hostSaleSigle(platform,urgenttype,cycle));
    	return page;
    }
    
    /**
     * 
     * excel 导出
     * http://192.168.7.32:8080/businessAnalysis/logisticsAnalysis/packageEfficacy/exportExcel?platform=&urgenttype=&cycle=&fileName=sigle
     * @param response
     * @param platform
     * @param urgenttype
     * @param cycle
     */
    
    
    @RequestMapping("/exportExcel")
    public void exportHostSaleSigle(HttpServletResponse response,
    		@RequestParam(value = "platform",required = false)String platform,
    		@RequestParam(value = "urgenttype", required = false) String urgenttype,
    		@RequestParam(value = "cycle", required = false) String cycle,
    		@RequestParam(value = "fileName", required = false) String fileName){
    	response.setCharacterEncoding("UTF-8");
    	response.setContentType("octets/stream");
    	String formatDate = DvDateUtils.format(new Date(), "yyyyMMddHHmmss");
    	Map<String,String> mapParameter=new HashMap<String, String>();
    	mapParameter.put("platform", platform);
    	mapParameter.put("urgenttype", urgenttype);
    	mapParameter.put("cycle", cycle);
    	
    	int tableFlag=0;
    	if("sigle".equals(fileName)){
    		fileName = "热销单品_"+formatDate;
    		tableFlag=1;
    	}else if("group".equals(fileName)){
    		fileName = "热销组合详情_"+formatDate;
    		tableFlag=2;
    	}else if("fail".equals(fileName)){
    		fileName = "集货失败明细_"+formatDate;
    		tableFlag=3;
    	}else if("refund".equals(fileName)){
    		fileName = "退货包裹明细_"+formatDate;
    		tableFlag=4;
    	}else if("overview".endsWith(fileName)){
    		fileName = "近30天物流效能_"+formatDate;
    		tableFlag=5;
    	}
    	
    	System.out.println("fileName=="+fileName);
        OutputStream out=null;
		try {
			String codedFileName = java.net.URLEncoder.encode(fileName,"UTF-8");
			response.addHeader("Content-Disposition", "attachment;filename="+codedFileName+".xls");
			out = response.getOutputStream();
			service.putDataOnOutputStream(tableFlag,out,mapParameter);
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				out.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
    	
    }
}
